#include "EditorNodeScalePropertyViewModel.h"

#include "Window/EditorWindowGroupModel.h"
#include "Window/EditorMainWindowModel.h"
#include "Pages/EditorPageModel.h"

#include "Scene/SceneNode.h"

void REditorNodeScalePropertyViewModel::BindModel(TSharedObjectPtr<REditorPropertyModel> InModel
        ,TSharedObjectPtr<REditorObjectPropertyAbilityViewModel> InAbilityViewModel)
{
    Super::BindModel(InModel,InAbilityViewModel);
    NodeScaleModel = InModel;
}

float REditorNodeScalePropertyViewModel::GetX() const
{
    return NodeScaleModel->GetX();
}

void REditorNodeScalePropertyViewModel::SetX(float InX)
{
    auto Page=REditorWindowGroupModel::Get()->GetFocusedPage();
    auto Opearation = NewObject<REditorNodeScalePropertyOperation>(Page);
    Opearation->Objects.Add(NodeScaleModel->Node);
    Opearation->ChangeValue(
        NodeScaleModel->Node
        ,REditorNodeScalePropertyOperation::EAxis::X
        ,NodeScaleModel->GetX()
        ,InX);

    Page->AddAndRedoOperation(Opearation);
}

float REditorNodeScalePropertyViewModel::GetY() const
{
    return NodeScaleModel->GetY();
}

void REditorNodeScalePropertyViewModel::SetY(float InY)
{
    auto Page=REditorWindowGroupModel::Get()->GetFocusedPage();
    auto Opearation = NewObject<REditorNodeScalePropertyOperation>(Page);
    Opearation->Objects.Add(NodeScaleModel->Node);
    Opearation->ChangeValue(
        NodeScaleModel->Node
        ,REditorNodeScalePropertyOperation::EAxis::Y
        ,NodeScaleModel->GetY()
        ,InY);

    Page->AddAndRedoOperation(Opearation);
}

float REditorNodeScalePropertyViewModel::GetZ() const
{
    return NodeScaleModel->GetZ();
}

void REditorNodeScalePropertyViewModel::SetZ(float InZ)
{
    auto Page=REditorWindowGroupModel::Get()->GetFocusedPage();
    auto Opearation = NewObject<REditorNodeScalePropertyOperation>(Page);
    Opearation->Objects.Add(NodeScaleModel->Node);
    Opearation->ChangeValue(
        NodeScaleModel->Node
        ,REditorNodeScalePropertyOperation::EAxis::Z
        ,NodeScaleModel->GetZ()
        ,InZ);

    Page->AddAndRedoOperation(Opearation);
}
